/**********************************************************
    COPYRIGHT
        KND, Inc. (c) 2011
    CLASS NAME
        platform_uart.h
    DEPENDENCY

    HISTORY
		08/19/2011, created by Guangxing Liu
**********************************************************/
#ifndef PLATFORM_UART_H
#define PLATFORM_UART_H

#include "lpc177x_8x_uart.h"
#include "lpc177x_8x_gpio.h"

#define  BAUD_9600 9600L
#define  BAUD_115200 115200L
#define TRUE 1
#define FALSE 0
#define MAX_DEV_NAME_LEN 16
#define UART_DEVICE "UART"//Device name lengh must be  less than MAX_DEV_NAME_LEN

#define SET_UART_LED GPIO_OutputValue(1,1<<12,1)
#define CLR_UART_LED GPIO_OutputValue(1,1<<12,0)


#define platform_uart_app_call_device_op_setrecvbuffer       "0_setrecvbuffer"
#define platform_uart_app_call_device_op_setsendbuffer       "1_setsendbuffer"
#define platform_uart_app_call_device_op_configuart            "2_configuart"

enum{
	TASK_PRIORITY_LOW,
	TASK_PRIORITY_NORMAL,
	TASK_PRIORITY_HIGH,
};

enum {
	TASK_TYPE_NULL,
	TASK_TYPE_TIMER,
	TASK_TYPE_CALLBACK
};


typedef void * DeviceHandle;

typedef struct DeviceInterface {
	DeviceHandle (*open)(void);
	int (*close)(DeviceHandle handle);
	 int (*ioctl)(DeviceHandle handle, const char *params);
	int (*read)(DeviceHandle handle, void  *buf, int len);
	int (*write)(DeviceHandle handle, void *buf, int len);
} DeviceInterface;


typedef struct _hyacinth_service_
{
	
	DeviceHandle hanle;                     //platform device handle
	char devname[MAX_DEV_NAME_LEN];//platform device name
	DeviceInterface device_interface;       // platform device interface
}hyacinth_service;


typedef enum{
	Platform_Uart_App_Call_None = 0,
	Platform_Uart_App_Call_SetRecvBuffer,
	Platform_Uart_App_Call_SetSendBuffer,
	Platform_Uart_App_Call_ConfigUart
}platform_uart_device_opt;

typedef struct _platform_uart_app_call_
{
	platform_uart_device_opt iOpt;
}platform_uart_app_call;


// Buffer size (2 ^ BUFFER_SIZE_EXPONENT)
#define BUFFER_SIZE_EXPONENT    8
#define BUFFER_SIZE             (1 << BUFFER_SIZE_EXPONENT)
#define BUFFER_SIZE_BM          (BUFFER_SIZE - 1)
//-----------------------------------------------------------------------------------------------------

// The buffers between the UART and the RF transceiver
typedef struct _platform_uart_buffer_{
	unsigned char  pBuffer[BUFFER_SIZE];
	unsigned char  inPos;
	unsigned char  length;
	unsigned char  finish;
	unsigned char uart_port;
	unsigned char ready;
	void (*call_back)();
} platform_uart_buffer;


typedef struct _platform_uart_config_{
	unsigned char uart_port;
	UART_CFG_Type UARTConfigStruct;
}platform_uart_config;


typedef struct _platform_uart_baudrate_{

	unsigned int uart0_baudrate;
	unsigned int uart1_baudrate;
	unsigned int uart2_baudrate;
	unsigned int uart3_baudrate;

}platform_uart_baudrate;


enum{	
	PORT_UART0,
	PORT_UART1,
	PORT_UART2,
	PORT_UART3,
	PORT_UART4
};























#endif

